var express = require('express');
const { find } = require('../database/model/stuModel.js');
var router = express.Router();
var stuModel = require('../database/model/stuModel.js') //引入Schema对象

/* GET home page. */
router.get('/demo1', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/demo', function(req, res, next) {
  res.send('新建路由文件');
});

router.get('/', function(req, res, next) {
  console.log(req.headers)
  stuModel.find().then(result=>{
    // console.log(result);
    // res.send({
    //   code:101,
    //   msg:'获取学员列表成功',
    //   data:result
    // })
  })
});

router.post('/', function(req, res, next) {
  new stuModel({  //实例化一条具体的数据
    name:"张三",
    score:100
  }).save().then(result=>{
    console.log(result);
    res.send({
      code:1,
      msg:'录入成功'
    })
  })
});


module.exports = router;
